package com.sina.shop.service.user;

import com.sina.shop.dao.user.UserDao;
import com.sina.shop.domain.user.User;
import com.sina.shop.service.ShopDataSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

import static com.sina.shop.service.ServiceConstant.SHOP_TX;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2017-09-21-12:16
 */
@Service("userService")
public class UserServiceImpl extends ShopDataSourceService implements UserService {

    @Qualifier("userDao")
    @Autowired
    private UserDao userDao;

    @Override
    @Transactional(value = SHOP_TX, readOnly = true, isolation = Isolation.READ_COMMITTED)
    public List<Map<String, Object>> getUserList(User criteria, long[] count) {

        if (count != null && count.length > 0) {
            count[0] = userDao.getUserCount(criteria);
        }

        return userDao.getUserList(criteria);
    }

    @Override
    @Transactional(value = SHOP_TX, readOnly = true, isolation = Isolation.READ_COMMITTED)
    public User getUserByNameAndPassword(String name, String password) {
        return userDao.getUserByNameAndPassword(name, password);
    }
}
